{% extends "base.html" %}

{% block title %}管理图书{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
    <h2 class="mb-0">图书总览</h2>
    <a href="{% url 'add_book' %}" class="btn btn-primary">
        <i class="fas fa-plus"></i> 添加新书
    </a>
</div>

<div class="card shadow-sm">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th scope="col">书名</th>
                        <th scope="col">作者</th>
                        <th scope="col">ISBN</th>
                        <th scope="col">库存</th>
                        <th scope="col" class="text-end">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for book in books %}
                    <tr>
                        <td><a href="{% url 'book_detail' book.pk %}">{{ book.title }}</a></td>
                        <td>{{ book.author }}</td>
                        <td>{{ book.isbn }}</td>
                        <td>{{ book.quantity }}</td>
                        <td class="text-end">
                            <a href="{% url 'edit_book' book.pk %}" class="btn btn-sm btn-outline-secondary">编辑</a>
                            <a href="{% url 'delete_book' book.pk %}" class="btn btn-sm btn-outline-danger">删除</a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="5" class="text-center">图书馆里还没有书。</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}